#ifndef MESSAGETEXTEDIT_H
#define MESSAGETEXTEDIT_H
#include<QTextEdit>
#include<QMouseEvent>
#include<QApplication>
#include<QDrag>
#include<QDragEnterEvent>
#include<QVector>
#include<QKeyEvent>
#include<QPixmap>
#include <QFileIconProvider>
#include<QPainter>
#include<QMimeData>
#include"global.h"
class MessageTextEdit:public QTextEdit
{
    Q_OBJECT
public:
    explicit MessageTextEdit(QWidget* parent=nullptr);
    ~MessageTextEdit();
    QVector<MsgInfo>getMsgList();
    void insertFileFromUrl(const QStringList &urls);
signals:
    void send();

protected:
    void dragEnterEvent(QDragEnterEvent*event);
    void dropEvent(QDropEvent*event);
    void keyPressEvent(QKeyEvent*event);
private:
    void insertImages(const QString &url);
    void insertTextFile(const QString& url);
    bool canInsertFromMimeData(const QMimeData *source) const;
    void insertFromMimeData(const QMimeData* source);

private:
    bool isImage(QString url);//判断是否为图片
    void insertMsgList(QVector<MsgInfo>&list,QString flag,QString text,QPixmap pix);

    QStringList getUrl(QString text);
    //获取图片图标及大小信息，并转化为图片
    QPixmap getFileIconPixmap(const QString &url);
    QString getFileSize(qint64 size);//获取文件大小
private slots:
    void textEditChanged();
private:
    QVector<MsgInfo> mMsgList;
    QVector<MsgInfo> mGetMsgList;

};

#endif // MESSAGETEXTEDIT_H
